﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _00365 {
	public partial class Login : System.Web.UI.Page {
		protected void Page_Load(object sender, EventArgs e) {

		}

		protected void btnLogOn_Click(object sender, EventArgs e) {

			Data.Login loggedUser;
			List<Data.Feature> permissions;
			bool success = Biz.Login.Authenticate(this.txtUserName.Text.Trim(), Biz.Sys.Encrypt(this.txtPassword.Text), out loggedUser, out permissions);
			if (success)
			{                
				Biz.Sys.SetLoggedUser(Session, loggedUser); 
				Biz.Sys.SetLoggedUserPermissions(Session, permissions);
                if (Request.QueryString.AllKeys.Contains("redirurl"))
                    Response.Redirect(Request.QueryString["redirurl"]);
                else
                    Response.Redirect(Page.ResolveUrl("~/Default.aspx"));
				
			}
			else
			{
				this.lblLoginFailed.Text = "Nome de usuário ou senha inválidos. Tente novamente.";
			}			
		}
	}
}